package com.sinosoft.dsp.persistence.hibernate.bo.impl;

import java.util.List;

import com.sinosoft.dsp.persistence.exception.SinoPersistenceException;
import com.sinosoft.dsp.persistence.hibernate.bo.SystemSecurityBo;
import com.sinosoft.dsp.persistence.hibernate.dao.CommonDao;
import com.sinosoft.dsp.system.entity.ISecurityUser;

public class SystemSecurityBoImpl implements SystemSecurityBo {
	private CommonDao dao;

	public CommonDao getDao() {
		return dao;
	}

	public void setDao(CommonDao dao) {
		this.dao = dao;
	}

	/**
	 * 通过登陆名称获得唯一的用户
	 * 
	 * @param loginName
	 * @return
	 * @throws SinoPersistenceException
	 */
	@Override
	public ISecurityUser findUserByLoginName(String loginName)
			throws SinoPersistenceException {
		String hql = "from SysUser u where u.loginName=? and u.state='0'";
		return dao.findUniqueResult(hql, loginName);
	}

	/**
	 * 通过用户ID获得用户拥有的导航ID集
	 * ?
	 * 
	 * @param userId
	 * @return
	 * @throws SinoPersistenceException
	 */
	@Override
	public List<?> getUserNaviIdSet(String userId)
			throws SinoPersistenceException {
		String hql = "select a.naviid from RoleFuncEntity a where a.sysRole in (select b.sysRole from UserRoleEntity b where b.sysUser.useruuid=?)";
		return dao.find(hql, userId);
	}

	/**
	 * 通过用户ID获得用户所在的组织机构ID集
	 * 
	 * @param userId
	 * @return
	 * @throws SinoPersistenceException
	 */
	@Override
	public List<?> getUserOrgIdSet(String userId)
			throws SinoPersistenceException {
		String hql = "select o.unituuid from SysOrg o,OrgUserEntity u where  u.sysUser.useruuid=? and u.sysOrg.unituuid = o.unituuid";
		return dao.find(hql, userId);
	}

	/**
	 * 通过用户ID获得用户角色ID集
	 * 
	 * @param userId
	 * @return
	 * @throws SinoPersistenceException
	 */
	@Override
	public List<?> getUserRoleIdSet(String userId)
			throws SinoPersistenceException {
		String hql = "select ur.sysRole.roleuuid from UserRoleEntity as ur where ur.sysUser.useruuid=?";
		return dao.find(hql, userId);
	}

}
